Cette page est pour n'importe qui voulant rendre son Ubuntu capable de s'authentifier auprès d'un serveur OpenLDAP.
L'utilisateur qui désire s'authentifier avec Sun Java Enterprise System Directory Server doit regarder la page sur la documentation en anglais.
Cette page explique la configuration d'une machine sous Ubuntu 14.04 / Linux Mint 17 afin d'authentifier les utilisateurs enregistrés dans un LDAP
Sur la machine cliente, installez les paquets présents dans les dépôts officiels.
sudo apt-get update sudo apt-get install libpam-ldap nscd
l'installation de nscd necessite de répondre à quelques question :
indiquer l'adresse de votre serveur :
ldap://xxx.xxx.xxx.xxx
ou
ldap://monldap.a.moi.com
pour indiquer un nom de domaine. Vous pouvez également indiquer plusieurs adresses comme un serveur principal et un serveur de secours, ou encore, l'IP privée puis l'IP publique de votre serveur (si vous avec par exemple à utiliser le même compte dans vos locaux ou à l'exterieur)
ldap://ipprivée ldap://ippublique
ldapi:///
proposée par défaut par
ldap://
(pas de i et seulement 2 slash)
vous devez renseigner le dn de votre base exemple
dc=test,dc=com
choisissez 3, la version 2 tends à devenir obsolète et est moins sécurisée
YES
No
Saisissez le compte admin de votre base Exemple :
"cn=admin,dc=test,dc=com"
puis le mot de passe de ce compte admin
En cas d'erreur vous pourrez toujours relancer la configuration avec la commande
sudo dpkg-reconfigure ldap-auth-config
TODO We have to adjust a few files to tell our authentication files that they can look to our LDAP server for authentication information.
First, edit the /etc/nsswitch.conf file. This will allow us to specify that the LDAP credentials should be modified when users issue authentication change commands.
sudo nano /etc/nsswitch.conf
The three lines we are interested in are the "passwd", "group", and "shadow" definitions. Modify them to look like this:
passwd: ldap compat group: ldap compat shadow: ldap compat
Next, we will add a value to our PAM configuration.
PAM, or Pluggable Authentication Modules, is a system that connects applications that can provide authentication to applications that require authentication.
PAM is already implemented on most computers, and works behind the scenes without needing user interaction. When we installed and configured our LDAP PAM module, most of the needed information was added to the configuration files.
Edit the /etc/pam.d/common-session file:
sudo nano /etc/pam.d/common-session
Add a line to the bottom of the configuration that reads:
session required pam_mkhomedir.so skel=/etc/skel umask=0022
This will create a home directory on the client machine when an LDAP user logs in who does not have a home directory.
We have to restart a service for these changes to be implemented:
sudo /etc/init.d/nscd restart
Permissions
During the LDAP server configuration, we created a group called "admin". This was not chosen at random. It coincides with the "admin" group that is created by default on Ubuntu machines.
The LDAP users that you added to the "admin" group will have access to the sudo command.
This is because we have a line that gives members of the "admin" group sudo access within the /etc/sudoers file. Edit the file by issuing this command:
sudo visudo
There is a line that reads:
%admin ALL=(ALL) ALL
Entries that begin with a percentage sign (%) specify a group instead of a user. If you wish to disable this functionality, or only grant specific users this functionality, comment out this line:
#%admin ALL=(ALL) ALL
Log In as an LDAP User
We have now configured our client machine enough to be able to log in as one of our LDAP users. This user does not have to exist on the client machine.
In a new terminal window (it is best to keep your original terminal window logged in, in case of a configuration mistake), ssh into the client machine using an LDAP user's credentials:
ssh LDAP_user@LDAP_client_IP_Address
You should be able to log in as if your user had been created locally. Issue the print working directory command:
pwd
You should see that the home directory you selected for your user on the LDAP server is being used on this machine. It has been created on-demand to serve the LDAP user.
If you log out and log in with a different LDAP user, you can see that there will be two home directory entries:
ls /home
user1 user2
If your user is part of the "admin" group and you didn't disable the ability in the previous section, you will have normal sudo access, otherwise, you will not.
If you issue the passwd command to change your password, you can see that it will be modifying your LDAP credentials:
passwd
Enter login(LDAP) password:
Restricting Access by Group
If you only want members of certain groups to be able to log into this specific machine, you can configure that restriction within the PAM files.
Edit the following file with root privileges:
sudo nano /etc/pam.d/common-auth
At the bottom, we will specify that PAM should look at the security access file to see how to restrict user logins. Add this to the bottom:
auth required pam_access.so
Save and close the file.
The file that PAM references for security information when that setting is configured is at /etc/security/access.conf. Open this file now, with root privileges:
sudo nano /etc/security/access.conf
We need to add a rule to the end of the file.
The dash (-) at the beginning of the line means this is a restriction. From the first colon (:) to the next colon, we specify who this rule applies to.
We specify that this applies to all users except root and the group "admin". Groups are given within parentheses.
From the second colon to the end of the line, we will specify under which circumstances the rule should apply. In our case, the restriction will apply in all circumstances but local logins.
-:ALL EXCEPT root (admin):ALL EXCEPT LOCAL
This will allow us to restrict logins to the "admin" group. We can add other groups or change the group.
This will also allow us to log in through the "console access" button on the DigitalOcean console if we somehow lock ourselves out of SSH.
Keep in mind that this will apply to all users, not just LDAP users. So any users you create on the client machine will need to be a member of one of the specified groups.
Il y a un nouvel outil dans Gutsy pour modifier les outils de pam et de nsswitch en même temps :
sudo auth-client-config -a -p lac_ldap
Malheureusement nous ne pouvons tester la configuration des paquets plus haut sans la modification de /etc/nsswitch.conf :
sudo vi /etc/nsswitch.conf
et remplacer compat par ldap files ou par cette commande dans vi :
:g/compat/s//files ldap/g
Votre fichier /etc/nsswitch.conf doit alors contenir les lignes suivantes :
passwd: files ldap group: files ldap shadow: files ldap
Pensez à redémarrer le démon nscd, qui garde en cache les résultats :
/etc/init.d/nscd restart ou
service nscd restart
Maintenant vous pouvez tester la configuration avec
les commandes plus bas (remplacer <someldapuser> par un nom d'utilisateur et <someldapgroup> par un nom de groupe présent dans votre serveur LDAP) :
getent passwd <someldapuser> getent group <someldapgroup>
Si vous avez une réponse dans les deux cas nsswitch.conf est correctement configuré la seule chose qui reste à faire est de configurer PAM.
Il est aussi possible de taper directement : getent passwd vous devez alors voir tous les utilisateurs de votre serveur ldap. Si ce n'est pas le cas, éditez et vérifiez le contenu des fichiers /etc/ldap/ldap.conf et /etc/libnss-ldap.conf. Pour modifier ce dernier utilsez la commande :
dpkg-reconfigure libnss-ldap
La configuration de PAM est divisée en 4 fichiers : common-account, common-auth, common-password and common-session
sudo vi /etc/pam.d/common-account
Changez la configuration par ces lignes :
account sufficient pam_ldap.so account required pam_unix.so
sudo vi /etc/pam.d/common-auth
Changez la configuration par ces lignes :
auth sufficient pam_ldap.so auth required pam_unix.so nullok_secure use_first_pass
sudo vi /etc/pam.d/common-password
Changez la configuration par ces lignes :
password sufficient pam_ldap.so password required pam_unix.so nullok obscure min=4 max=8 md5
Pour l'utilisation de mots de passe plus difficiles à casser, il vous suffit d'installer le paquet libpam-cracklib :
sudo apt-get install libpam-cracklib
Vous avez besoin de modifier la configuration du fichier /etc/pam.d/common-password :
sudo vi /etc/pam.d/common-password
Changez la configuration par ces lignes :
password required pam_cracklib.so retry=3 minlen=6 difok=3 password sufficient pam_ldap.so use_authtok nullok md5 password required pam_unix.so use_authtok use_first_pass
sudo vi /etc/pam.d/common-session
Changez la configuration par ces lignes :
session sufficient pam_ldap.so session required pam_unix.so
Si vous voulez que la création automatique du répertoire home soit faite à la première connexion vous allez devoir éditer common-session encore une fois :
sudo vi /etc/pam.d/common-session
Changez la configuration par ces lignes :
session required pam_unix.so session required pam_mkhomedir.so skel=/etc/skel/ session optional pam_ldap.so
Je me permets d'avancer une autre méthode que j'ai suivi, celle énoncée ici n'ayant pas fonctionné.
Tout d'abord pour installer le client sur une ubuntu/mint 14.04, j'ai suivi ce tuto pour activer l'authentification lorsque le serveur LDAP est accessible
Pour configurer le client ldap sur ma distrib ubuntu, j'ai suivi ce tuto qui a fonctionné comme un charme :
et pour la conf de mes laptop, j'ai ajouté ceci
sudo apt-get install nss-updatedb libnss-db libpam-ccreds nslcd sudo nss_updatedb ldap
Editer le fichier /etc/nsswitch.conf tel que:
passwd: files ldap [NOTFOUND=return] db group: files ldap [NOTFOUND=return] db
ensuite éditer etc/pam.d/common-account pour remplacer la ligne
account [success=1 default=ignore] pam_ldap.so
par
account [success=1 authinfo_unavail=1 default=ignore] pam_ldap.so
il suffira maintenant d'un :
sudo nss_updatedb ldap
pour mettre à jour la copie locale des users LDAP
Source : traduction de https://wiki.ubuntu.com/LDAPClientAuthentication
Contributeur principal : phetu (traduction).